package asapIs134CK.womi.client.event;


import java.util.Iterator;
import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.VerticalPanel;

public class ListWomiEventDisplay extends Composite{
	private VerticalPanel panel;
	

	/**
	 * Create a remote service proxy to talk to the server-side Greeting service.
	 */
	private final RCPEventServiceAsync eventService = GWT
			.create(RCPEventService.class);
	
	public ListWomiEventDisplay(){
		panel = new VerticalPanel();
		panel.addStyleName("Events");
		initWidget(panel);
		
		AsyncCallback<List> callback = new AsyncCallback<List>() {
			public void onFailure(Throwable caught) {
				// Show the RPC error message to the user
				Window.alert("The server could not be reached, please check your network connection.");
			}

			public void onSuccess(List result) {
				if(result != null){
					Iterator ite = result.iterator();
					while(ite.hasNext()){
						panel.add(new WomiEventDisplay((WomiEvent) ite.next()));
					}
				}
			}
		};
		eventService.getEvents(callback);
	}

}
